<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('学习资料列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>类型：</p>
                                <select name="type" th:with="type=${@dict.getType('material_res_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <p>学习范围：</p>
                                <select name="range" th:with="type=${@dict.getType('material_range')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <p>审核状态：</p>
                                <select name="approveSt" th:with="type=${@dict.getType('common_support')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <p>标题：</p>
                                <input type="text" name="name"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="dict:material:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="dict:material:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="dict:material:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-success multiple disabled" onclick="batchApprove()" shiro:hasPermission="dict:material:edit">
                    <i class="fa fa-plus"></i> 批量审核
                </a>
                <a class="btn btn-primary multiple disabled" onclick="addToMaterialTopic()" shiro:hasPermission="dict:material:edit">
                    <i class="fa fa-edit"></i> 加入专题
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="dict:material:export">
                    <i class="fa fa-download"></i> 导出
                 </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('dict:material:edit')}]];
        var removeFlag = [[${@permission.hasPermi('dict:material:remove')}]];
        var typeDatas = [[${@dict.getType('material_res_type')}]];
        var rangeDatas = [[${@dict.getType('material_range')}]];
        var approveStDatas = [[${@dict.getType('common_support')}]];
        var freeDatas = [[${@dict.getType('common_support')}]];
        var prefix = ctx + "dict/material";
        var resPrefix = ctx + "dict/res";

        $(function() {
            var options = {
                sortName: "createdTime",
     		    sortOrder: "desc",
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "学习资料",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id', 
                    title : 'id',
                    visible: false
                },
                {
                    field : 'type', 
                    title : '类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(typeDatas, value);
                    }
                },
                {
                    field : 'range', 
                    title : '学习范围',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(rangeDatas, value);
                    }
                },
                {
                    field : 'name', 
                    title : '标题'
                },
                {
                    field : 'tag', 
                    title : '标签'
                },
                {
                    field : 'kkid', 
                    title : '上传用户'
                },
                {
                    field : 'approveSt', 
                    title : '审核状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(approveStDatas, value);
                    }
                },
                {
                    field : 'price', 
                    title : '价格'
                },
                {
                    field : 'ad',
                    title : '是否广告',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(freeDatas, value);
                    }
                },
                {
                    field : 'createdTime', 
                    title : '上传时间'
                },
                {
                    field : 'payCount', 
                    title : '付费次数'
                },
                {
                    field : 'share', 
                    title : '分享次数'
                },
                {
                    field : 'praise', 
                    title : '点赞次数'
                },
                {
                    field : 'source', 
                    title : '来源'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        if(row.approveSt == 0){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="approve(\'' + row.id + '\', 1)"><i class="fa fa-edit"></i>审核通过</a> ');
                        }
                        if(row.approveSt == 1){
                            actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="approve(\'' + row.id + '\', 0)"><i class="fa fa-remove"></i>取消审核</a> ');
                        }
                        actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="res(\'' + row.id + '\')"><i class="fa fa-list-ul"></i>资源列表</a> ');
		                return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
        /*学习资料，资源列表*/
		function res(materialId) {
		    var url = resPrefix + "/" + materialId;
		    $.modal.openTab("学习资料资源列表", url);
		}

		/*学次资料，审核*/
		function approve(materialId, approveSt) {
		    let msg = approveSt == 1?"确定要审核通过吗?":"确定要取消审核吗?";
		    $.modal.confirm(msg, function() {
				$.operate.post(prefix + "/approve/" + materialId, { "approveSt": approveSt});
		    })
		}

		function batchApprove(){

            var rows = $.table.selectColumns("id");
			if (rows.length == 0) {
       			$.modal.alertWarning("请至少选择一条记录");
       			return;
       		}
       		$.modal.confirm("确定要审核通过选中的" + rows.length + "条数据吗?", function() {
                var data = {"ids": rows.join()};
			    $.operate.post(prefix + "/batchApprove", data);
       		})

		}

		function addToMaterialTopic() {
            var rows = $.table.selectColumns("id");
			if (rows.length == 0) {
       			$.modal.alertWarning("请至少选择一条记录");
       			return;
       		}
       		var addToMaterialTopicUrl = prefix + "/materialTopic/" + rows.join();
       		$.modal.open("加入专题", addToMaterialTopicUrl);
		}

        
    </script>
</body>
</html>